<?php
require("db_config.php");
if(isset($_POST["myID"])){

$software_id=$_POST["myID"];

$con = mysql_connect($db_host,$db_user,$db_password);
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db($db_name, $con);

$result = mysql_query("SELECT id FROM software where software_key='".$software_id."';");

$vi=rand_string(8);
$row = mysql_fetch_array($result);
if($row != null && $row != ""){
	mysql_query("insert into audit (timestamp,software_id,vi,action) values (".$_SERVER['REQUEST_TIME'].",'".$row['id']."','".$vi."','TOKEN-IO:ACCESS');");
	echo $vi;
}

mysql_close($con);
}

function rand_string( $length ) {
		$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";	
		$str="";
		$size = strlen( $chars );
		for( $i = 0; $i < $length; $i++ ) {
			$str .= $chars[ rand( 0, $size - 1 ) ];
		}
		
		return $str;
	}

?>